Skip to content

[Plugins] Auto-approve run_tool's native prompt under HITL (Claude Code PreToolUse hook)#23

Merged
swarup-padhi-glean merged 4 commits into
mainfrom
auto-approve-run-tool-hook
Jun 24, 2026
Merged

[Plugins] Auto-approve run_tool's native prompt under HITL (Claude Code PreToolUse hook)#23
swarup-padhi-glean merged 4 commits into
mainfrom
auto-approve-run-tool-hook

Conversation

@swarup-padhi-glean

@swarup-padhi-glean swarup-padhi-glean commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What & why

When HITL is enabled, the Glean plugin's own elicitation prompt is the approval gate for run_tool. Claude Code still shows its own native "Allow this tool?" prompt on top of it — a redundant double-prompt. This adds a Claude Code PreToolUse hook that auto-approves run_tool's native prompt when HITL is active, leaving the HITL elicitation as the single gate.

How it's gated (safety)

The hook emits permissionDecision: "allow" only when both:

  • the tool is Glean's run_tool (the tool name carries glean and resolves to run_tool), and
  • ENABLE_HITL=true (read from the plugin's .mcp.json, since the hook process doesn't inherit the MCP server env).

run_tool is read-only only while HITL gates it. This hook runs only under Claude Code, which always advertises the elicitation capability, so ENABLE_HITL=truerun_tool's HITL prompt is active — it can never auto-approve an ungated write. When ENABLE_HITL isn't true, the hook does nothing and the normal permission flow runs. A stricter deny/ask from any other PreToolUse hook still wins.

Scope

  • Claude Code only. Cursor/Codex also have PreToolUse hooks, but they don't surface the redundant native prompt, so there's nothing to suppress there.
  • run_tool only for now. Extending to other read-only tools (find_skills, setup) and other surfaces is a follow-up.

Also

  • Fixes a duplicate-hooks load error: removed the redundant hooks field from the Claude manifest (the host auto-loads hooks/hooks.json; declaring it again double-loaded and failed).

Tests

Unit tests for the hook: allows Glean run_tool when HITL on; never allows when HITL off (safety); ignores a non-Glean run_tool; ignores Glean tools other than run_tool.

…HITL

When HITL is on, run_tool draws two prompts: Claude Code's native
allow-this-tool gate AND the plugin's own HITL elicitation. readOnlyHint
(the intended suppressor) is advisory and Claude Code doesn't honor it,
and a plugin can't write to permissions.allow. This ships a plugin
PreToolUse hook that returns permissionDecision:allow for run_tool so the
native prompt is suppressed and HITL is the single gate.

Gated behind HITL_AUTO_APPROVE (default false) AND only when
ENABLE_HITL=true — never auto-approves an ungated write. Hook reads both
flags from the plugin .mcp.json (it doesn't inherit the server env).
Claude Code only; Cursor/Codex unaffected.
swarup-padhi-glean added a commit that referenced this pull request Jun 22, 2026
Three open PRs (#21/#22/#23) were stacked on 0.2.31; move this one to the
next version so it stays strictly above main and mergeable regardless of
order against a single 0.2.31 PR.

@eshwar-sundar-glean eshwar-sundar-glean left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge now and take up other surfaces in next PR if needed, it will be good to maintain consistency across surfaces where applicable


const toolName = String(input.tool_name ?? "");
// Only this plugin's run_tool meta-tool (exposed as mcp__<server>__run_tool).
if (!toolName.endsWith("run_tool")) process.exit(0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for both glean and run_tool?

}

const hitlOn = env.ENABLE_HITL === "true";
const autoApprove = env.HITL_AUTO_APPROVE === "true";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont think we need a new flag here, just use ENABLE_HITL

@@ -1,8 +1,9 @@
{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check what does it mean to support it in Codex and Cursor as well?

Cursor - https://cursor.com/docs/hooks#pretooluse
Codex - https://developers.openai.com/codex/hooks#pretooluse

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @eshwar-sundar-glean we don't have this problem in cursor/codex. We don't need to solve there.

…eview

- Scope the PreToolUse hook to glean's read-only tools (run_tool, find_skills,
  setup) and require the tool name to carry 'glean' (review: check glean too).
- Gate on ENABLE_HITL only; drop the HITL_AUTO_APPROVE flag (review). Safe
  because the hook runs only under Claude Code, which always advertises
  elicitation, so ENABLE_HITL=true means run_tool's HITL prompt is active.
- Fix duplicate-hooks load error: remove the redundant 'hooks' field from the
  claude manifest (hooks/hooks.json is auto-loaded by the host).
- Merge main; align all manifests to 0.2.33.
…2.34

Per team consensus, ship the Claude Code PreToolUse auto-approve hook for
run_tool only; find_skills/setup (and other surfaces) are a follow-up.
Keeps the glean-scoped check and ENABLE_HITL-only gate.
…-hook

# Conflicts:
#	plugins/glean/.claude-plugin/plugin.json
#	plugins/glean/.codex-plugin/plugin.json
#	plugins/glean/.cursor-plugin/plugin.json
@swarup-padhi-glean swarup-padhi-glean changed the title [Plugins] Prototype: auto-approve run_tool under HITL via PreToolUse hook (flag-gated) [Plugins] Auto-approve run_tool's native prompt under HITL (Claude Code PreToolUse hook) Jun 24, 2026
@swarup-padhi-glean swarup-padhi-glean merged commit 7d5973c into main Jun 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants